/**
 * @author Daniela
 */
$(document).ready(function(){
    displayData("propiedades","propiedades");
    displayData("destacados","destacados");
    displayData("scategoria","categorias");
    displayData("soperacion","operaciones");
    $cookie=getCookie("style");
    if ($cookie==null){
    	setCookie("style","css/style1.css", 3);
    	$cookie=getCookie("style");
    	$('head').append($('<link />',{id:'tema',rel: 'stylesheet',type: "text/css",href: $cookie}));
    }
    else{
    	$('head').append($('<link />',{id:'tema',rel: 'stylesheet',type: "text/css",href: $cookie}));
    }
  
});

function displayData($parent,$XMLFile){
	  
    xml = loadXMLDoc("xml/"+$XMLFile+".xml");
  
      xsl = loadXMLDoc("xsl/"+$XMLFile+".xsl");
     
    // code for IE
    if (window.ActiveXObject) {
        ex = xml.transformNode(xsl);
        document.getElementById($parent).innerHTML = ex;
    }
    // code for Mozilla, Firefox, Opera, etc.
    else {
    	
        if (document.implementation && document.implementation.createDocument) {
        	
            xsltProcessor = new XSLTProcessor();  
            
            xsltProcessor.importStylesheet(xsl);
             
            resultDocument = xsltProcessor.transformToFragment(xml, document);
                   
			exampleDiv = document.getElementById($parent);
			exampleDiv.innerHTML = "";
            exampleDiv.appendChild(resultDocument);
            
        }
       }
          
}
function loadXMLDoc(dname){
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    }
    else {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET", dname, false);
    xhttp.send("");
    return xhttp.responseXML;
}

function getCookie(c_name){
	var c_value = document.cookie;
	var c_start = c_value.indexOf(" " + c_name + "=");
	if (c_start == -1){
		c_start = c_value.indexOf(c_name + "=");
	}
	if (c_start == -1){
		c_value = null;
	}
	else{
		c_start = c_value.indexOf("=", c_start) + 1;
		var c_end = c_value.indexOf(";", c_start);
		if (c_end == -1){
			c_end = c_value.length;
		}
		c_value = unescape(c_value.substring(c_start,c_end));
		}
	return c_value;
}
		
function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}